package scigest.core;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.commons.configuration.PropertiesConfiguration;

public class ConfigReader {

    private static Configuration config = null;

    public static Configuration load() {

        if (config != null)
            return config;

        String proploc = System.getProperty("properties.location");
        if (proploc != null) {
            System.out.println("properties.location = " + proploc);
            try {
                config = new PropertiesConfiguration(proploc);
            }
            catch (ConfigurationException e) {
                e.printStackTrace();
            }
        } else {
            try {
                config = new PropertiesConfiguration("/esg/scigest/application.properties");
            }
            catch (ConfigurationException e) {
                String devPath = System.getProperty("user.home") + "/" +
                    "scigest/resources/application.properties";
                try {
                    config = new PropertiesConfiguration(devPath);
                } catch (ConfigurationException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }
            }
        }
        
        return config;
    }
}
